<template>
  <div>
    <div>
      <m-header></m-header>
      <div class="content-wrap">
        <div class="head">
          <p>查疾病</p>
        </div>
        <div class="choose">
          <div class="class">
            <p class="title">分类</p>
            <div
              class="flex-vertical"
              @click="changeClass(index + 1)"
              v-for="(item, index) in classList"
              :key="index"
            >
              <p :class="index + 1 == classActive ? 'active' : ''">
                {{ item }}
              </p>
            </div>
          </div>
          <div class="type">
            <p class="title">类型</p>
            <div class="typeWrap">
              <div
                @click="changeType(index, item.id)"
                v-for="(item, index) in typeList"
                :key="index"
              >
                <p :class="index == typeActive ? 'active' : 'aa'">
                  {{ item.typeName }}
                </p>
              </div>
            </div>
          </div>
        </div>
        <div class="content-wrap">
          <div class="content">
            <div class="item" v-for="item in diseaseList" :key="item.id">
              <p>
                <router-link :to="'/diseaseDetail?id=' + item.id">
                  {{ item.diseaseName }}
                </router-link>
              </p>
            </div>
          </div>
        </div>
      </div>
      <bottom></bottom>
    </div>
  </div>
</template>

<script>
import mHeader from "@/components/header.vue";
import bottom from "@/components/bottom.vue";

export default {
  components: {
    mHeader,
    bottom,
  },
  data() {
    return {
      classList: ["按类型", "按部位", "按科室"],
      classActive: "1",
      typeList: [
        "按类型"
      ],
      typeActive: "0",
      diseaseList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.HttpService.getDiseaseClass({ DiseaseType: this.classActive }).then(
        (res) => {
          console.log(res);
          this.typeList = res.data;
          let initDisease = "";
          initDisease = res.data[0];
          // 获取类型下的所有疾病
          this.HttpService.getDiseaseByType({ type: initDisease.id }).then(
            (res) => {
              console.log(res);
              this.diseaseList = res.data;
            }
          );
        }
      );
    },
    changeClass(index) {
      this.classActive = index;
      this.typeActive = "0";
      this.HttpService.getDiseaseClass({ DiseaseType: this.classActive }).then(
        (res) => {
          console.log(res);
          this.typeList = res.data;
          let initDisease = "";
          initDisease = res.data[0];
          this.HttpService.getDiseaseByType({ type: initDisease.id }).then(
            (res) => {
              console.log(res);
              this.diseaseList = res.data;
            }
          );
        }
      );
    },
    changeType(index, type) {
      this.typeActive = index;
      this.HttpService.getDiseaseByType({ type: type }).then((res) => {
        console.log(res);
        this.diseaseList = res.data;
      });
    },
  },
};
</script>

<style lang='less' scoped>
.active {
  background-color: var(--theme-color) !important;
  color: #fff;
}
.content-wrap {
  margin-top: 20px;
  background-color: #fff;
  min-height: 600px;
  border-radius: 10px;
  .head {
    line-height: 60px;
    border-bottom: 1px solid #eee;
    p {
      font-weight: bold;
      font-size: 17px;
      margin-left: 30px;
      // border-bottom: 3px solid var(--theme-color);
    }
  }
  .choose {
    border-bottom: 1px solid #eee;
    .class {
      margin: 30px 0px;
      display: flex;
      align-items: center;
      .title {
        font-weight: bold;
        width: 120px;
        text-align: center;
      }
      div {
        p {
          cursor: pointer;
          text-align: center;
          background-color: #f5f5f5;
          line-height: 35px;
          padding: 0px 10px;
          border-radius: 3px;
          margin-right: 15px;
        }
      }
    }
    .type {
      display: flex;
      align-items: center;
      margin: 30px 0px;
      .typeWrap {
        display: flex;
      }
      .title {
        font-weight: bold;
        min-width: 120px;
        text-align: center;
      }
      div {
        flex-wrap: wrap;
        p {
          cursor: pointer;
          text-align: center;
          background-color: #f5f5f5;
          line-height: 35px;
          padding: 0px 10px;
          border-radius: 3px;
          margin-right: 15px;
          margin-top: 10px;
        }
      }
    }
  }
  .content-wrap {
    .content {
      display: flex;
      flex-wrap: wrap;
      position: relative;
      .item {
        line-height: 70px;
        margin-right: 80px;
        color: #000;
        position: relative;
        cursor: pointer;
        a{
          color:#000;
        }
      }
      .item:before {
        content: ".";
        position: absolute;
        top: -5px;
        left: -10px;
        font-size: 20px;
        font-weight: 600;
        color: #ccc;
      }
    }
  }
}
</style>
